package com.net.xpay.common.manager.impl.admin.rbac;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.net.common.annotation.ReadTransactional;
import com.net.common.dao.BasicMapper;
import com.net.common.dao.OrderCondition;
import com.net.common.manager.AbstractManager;
import com.net.xpay.common.dao.admin.rbac.MenuMapper;
import com.net.xpay.common.domain.admin.rbac.Menu;
import com.net.xpay.common.manager.admin.rbac.MenuManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;


@Component
@ReadTransactional
public class MenuManagerImpl extends AbstractManager<Menu> implements MenuManager{

    @Autowired
    private MenuMapper mapper;


    @Override
    protected BasicMapper<Long, Menu> getMapper() {
        return mapper;
    }

    @Override
    public List<Menu> findByAdminUserId(Long adminUserId) {
        Preconditions.checkArgument(adminUserId != null);
        return nonEmptyList(mapper.findByAdminUserId(adminUserId));
    }

    @Override
    public List<Menu> findByPid(Long pid) {
        Preconditions.checkArgument(pid != null);
        Menu condition = new Menu();
        condition.setPid(pid);
        return listByCondition(condition, new ArrayList<>());
    }

    @Override
    public List<Menu> listAll() {
        Menu condition = new Menu();
        return listByCondition(condition, Lists.newArrayList(new OrderCondition("`sort`", "asc")));
    }

    @Override
    public List<Menu> listNoButtonMenu() {
        return nonEmptyList(mapper.listNoButtonMenu());
    }
}
